var t = s(require("../../../@babel/runtime/regenerator")),
  e = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = s(require("../../../config/page")),
  r = s(require("../../../config/index")),
  n = require("@/services/base/api"),
  i = require("@/utils/jump");
function s(t) {
  return t && t.__esModule ? t : { default: t };
}
var o = require("dayjs"),
  u = 0;
Page({
  data: {
    position: !1,
    background: "#FAF3E8",
    titleColor: "#000",
    titles: ["常设展览", "临时展览"],
    titleIndex: 0,
    swiperCurrent: 0,
    defaultImg: r.default.defaultImg,
    shows: [],
    historys: [],
    showQuery: { rn: 5, pn: 1 },
    hisQuery: { rn: 5, pn: 1 },
    hisLastPage: !1,
    showLastPage: !1,
    showLoad: !1,
    hisLoad: !1,
    load: !0,
    navBarHeight: 0,
    swiperTop: 0,
    CDN: r.default.CDN,
    height: 0,
    isFormDetailPage: !1,
    times: 0,
  },
  toDetail: function (t) {
    var e = t.currentTarget.dataset.item.exhibition_id;
    (0, i.navigateTo)(a.default.PAGE_RECOMMEND_EXHIBITION_CARD, { id: e });
  },
  onShow: function () {
    this.getShowListData();
  },
  onUnload: function () {
    this.setData({ isFormDetailPage: !1 });
  },
  onLoad: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var r, n;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                (r = a.createSelectorQuery().in(a))
                  .select("#exhTitle")
                  .boundingClientRect(),
                  (n = new Date().getTime()),
                  r.exec(function (t) {
                    u = t[0].height;
                    var e = getApp().globalSystemInfo,
                      r = e.navBarHeight;
                    e.ios && (r += e.navBarExtendHeight);
                    var i = wx.getSystemInfoSync().windowHeight - r - u;
                    a.setData({
                      height: i,
                      swiperTop: u,
                      navBarHeight: r,
                      times: n,
                    });
                  });
              case 4:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  onShareAppMessage: function () {
    return {
      title: r.default.share.title,
      imageUrl: r.default.share.pic,
      path: a.default.PAGE_RECOMMEND_EXHIBITION,
    };
  },
  changeTitle: function (t) {
    var e = 0;
    t.currentTarget
      ? ((e = t.currentTarget.dataset.index),
        this.setData({ titleIndex: e, swiperCurrent: e }))
      : (this.setData({ titleIndex: t }),
        1 === this.data.titleIndex &&
          0 === this.data.historys.length &&
          this.getHistoryListData());
  },
  changeCurrent: function (t) {
    var e = t.detail.current;
    this.changeTitle({ currentTarget: { dataset: { index: e } } }),
      this.getHistoryListData();
  },
  onHisBottomFunc: function () {
    this.getHistoryListData();
  },
  onShowBottomFunc: function () {
    this.getShowListData();
  },
  getShowListData: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var r, i, s, o, u, h, d;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                if (!a.data.showLastPage) {
                  t.next = 2;
                  break;
                }
                return t.abrupt("return");
              case 2:
                return (
                  (s = a.data.showQuery),
                  (t.next = 5),
                  (0, n.postExhibitionSearch)({
                    pn: s.pn,
                    rn: s.rn,
                    category: 1,
                  })
                );
              case 5:
                (o = t.sent),
                  (u =
                    null != o &&
                    null !== (r = o.data) &&
                    void 0 !== r &&
                    r.total
                      ? o.data.total
                      : 0),
                  (h =
                    null != o && null !== (i = o.data) && void 0 !== i && i.list
                      ? o.data.list
                      : []),
                  a.setData({
                    shows: a.data.shows.concat(h),
                    showLoad: !1,
                    load: !1,
                    "showQuery.pn": s.pn + 1,
                  }),
                  (d = a.data.shows),
                  a.setData({ showLastPage: d.length >= u });
              case 11:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  getHistoryListData: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var r, i, s, u, h, d, l;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                if (!a.data.hisLastPage) {
                  t.next = 2;
                  break;
                }
                return t.abrupt("return");
              case 2:
                return (
                  (s = a.data.hisQuery),
                  (t.next = 5),
                  (0, n.postExhibitionSearch)({
                    pn: s.pn,
                    rn: s.rn,
                    category: 2,
                  })
                );
              case 5:
                (u = t.sent),
                  (h =
                    null != u &&
                    null !== (r = u.data) &&
                    void 0 !== r &&
                    r.total
                      ? u.data.total
                      : 0),
                  (d =
                    null != u && null !== (i = u.data) && void 0 !== i && i.list
                      ? u.data.list
                      : []).map(function (t) {
                    return (
                      t.category && 2 === t.category && t.start_day && t.end_day
                        ? o().isBefore(t.start_day)
                          ? (t.onShow = 0)
                          : o().isAfter(t.start_day) && o().isBefore(t.end_day)
                            ? (t.onShow = 1)
                            : o().isAfter(t.end_day) && (t.onShow = 2)
                        : (t.onShow = 3),
                      t
                    );
                  }),
                  a.setData({
                    historys: a.data.historys.concat(d),
                    hisLoad: !1,
                    load: !1,
                    "hisQuery.pn": s.pn + 1,
                  }),
                  (l = a.data.historys),
                  a.setData({ hisLastPage: l.length >= h });
              case 12:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
});
